﻿using PersonalAlbum.Controllers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting.Web;
using System;
using System.ComponentModel;
using System.Web.Mvc;
using System.Web;

namespace UnitTests
{


    /// <summary>
    ///This is a test class for AccountControllerTest and is intended
    ///to contain all AccountControllerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class AccountControllerTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Logout
        ///</summary>
        // TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,
        // http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,
        // whether you are testing a page, web service, or a WCF service.
        [TestMethod()]
        [HostType("ASP.NET")]
        [AspNetDevelopmentServerHost("%PathToWebRoot%\\ImagesSite\\ImagesSite", "/")]
        [UrlToTest("http://localhost:52161/")]
        public void LogoutTest()
        {
            PersonalAlbum.Controllers.AccountController target = new PersonalAlbum.Controllers.AccountController(); // TODO: Initialize to an appropriate value
            var actual = target.Logout();
        }

        /// <summary>
        ///A test for Login
        ///</summary>
        [TestMethod()]
        [HostType("ASP.NET")]
        [AspNetDevelopmentServerHost("%PathToWebRoot%\\ImagesSite\\ImagesSite", "/")]
        [UrlToTest("http://localhost:52161/")]
        public void LoginTest_With_Return_Url()
        {
            PersonalAlbum.Controllers.AccountController target = new PersonalAlbum.Controllers.AccountController();
            string username = "tal";
            string password = "r";
            System.Nullable<bool> rememberMe = new System.Nullable<bool>(); // TODO: Initialize to an appropriate value
            string returnUrl = Guid.NewGuid().ToString();
            System.Web.Mvc.JsonResult actual;
            actual = target.Login(username, password, rememberMe, returnUrl);
            Assert.IsNotNull(actual);
            bool successFound = false;
            bool returnUrlFound = false;
            foreach (PropertyDescriptor p in TypeDescriptor.GetProperties(actual.Data))
            {
                if (p.Name == "success")
                {
                    successFound = true;
                    Assert.AreEqual("true", p.GetValue(actual.Data).ToString());
                }
                if (p.Name == "returnUrl")
                {
                    returnUrlFound = true;
                    Assert.AreEqual(returnUrl, p.GetValue(actual.Data).ToString());
                }
            }
            Assert.IsTrue(successFound);
            Assert.IsTrue(returnUrlFound);
        }


        /// <summary>
        ///A test for Login
        ///</summary>
        [TestMethod()]
        [HostType("ASP.NET")]
        [AspNetDevelopmentServerHost("%PathToWebRoot%\\ImagesSite\\ImagesSite", "/")]
        [UrlToTest("http://localhost:52161/")]
        public void LoginTest_Null_User_Name()
        {
            PersonalAlbum.Controllers.AccountController target = new PersonalAlbum.Controllers.AccountController();
            string username = null;
            string password = "r";
            System.Nullable<bool> rememberMe = new System.Nullable<bool>(); // TODO: Initialize to an appropriate value
            string returnUrl = Guid.NewGuid().ToString();
            System.Web.Mvc.JsonResult actual;
            actual = target.Login(username, password, rememberMe, returnUrl);
            Assert.IsNotNull(actual);
            bool invalidFound = false;
            bool messageFound = false;
            foreach (PropertyDescriptor p in TypeDescriptor.GetProperties(actual.Data))
            {
                if (p.Name == "invalid")
                {
                    invalidFound = true;
                    Assert.AreEqual("true", p.GetValue(actual.Data).ToString());
                }
                if (p.Name == "message")
                {
                    messageFound = true;
                    Assert.IsTrue(p.GetValue(actual.Data).ToString().Length > 0);
                }
            }
            Assert.IsTrue(invalidFound);
            Assert.IsTrue(messageFound);
        }

        [TestMethod()]
        [HostType("ASP.NET")]
        [AspNetDevelopmentServerHost("%PathToWebRoot%\\ImagesSite\\ImagesSite", "/")]
        [UrlToTest("http://localhost:52161/")]
        public void LoginTest_Empty_User_Name()
        {
            PersonalAlbum.Controllers.AccountController target = new PersonalAlbum.Controllers.AccountController();
            string username = "";
            string password = "r";
            System.Nullable<bool> rememberMe = new System.Nullable<bool>(); // TODO: Initialize to an appropriate value
            string returnUrl = Guid.NewGuid().ToString();
            System.Web.Mvc.JsonResult actual;
            actual = target.Login(username, password, rememberMe, returnUrl);
            Assert.IsNotNull(actual);
            bool invalidFound = false;
            bool messageFound = false;
            foreach (PropertyDescriptor p in TypeDescriptor.GetProperties(actual.Data))
            {
                if (p.Name == "invalid")
                {
                    invalidFound = true;
                    Assert.AreEqual("true", p.GetValue(actual.Data).ToString());
                }
                if (p.Name == "message")
                {
                    messageFound = true;
                    Assert.IsTrue(p.GetValue(actual.Data).ToString().Length > 0);
                }
            }
            Assert.IsTrue(invalidFound);
            Assert.IsTrue(messageFound);
        }

        [TestMethod()]
        [HostType("ASP.NET")]
        [AspNetDevelopmentServerHost("%PathToWebRoot%\\ImagesSite\\ImagesSite", "/")]
        [UrlToTest("http://localhost:52161/")]
        public void LoginTest_Null_Password()
        {
            PersonalAlbum.Controllers.AccountController target = new PersonalAlbum.Controllers.AccountController();
            string username = "tal";
            string password = null;
            System.Nullable<bool> rememberMe = new System.Nullable<bool>(); // TODO: Initialize to an appropriate value
            string returnUrl = Guid.NewGuid().ToString();
            System.Web.Mvc.JsonResult actual;
            actual = target.Login(username, password, rememberMe, returnUrl);
            Assert.IsNotNull(actual);
            bool invalidFound = false;
            bool messageFound = false;
            foreach (PropertyDescriptor p in TypeDescriptor.GetProperties(actual.Data))
            {
                if (p.Name == "invalid")
                {
                    invalidFound = true;
                    Assert.AreEqual("true", p.GetValue(actual.Data).ToString());
                }
                if (p.Name == "message")
                {
                    messageFound = true;
                    Assert.IsTrue(p.GetValue(actual.Data).ToString().Length > 0);
                }
            }
            Assert.IsTrue(invalidFound);
            Assert.IsTrue(messageFound);
        }

        [TestMethod()]
        [HostType("ASP.NET")]
        [AspNetDevelopmentServerHost("%PathToWebRoot%\\ImagesSite\\ImagesSite", "/")]
        [UrlToTest("http://localhost:52161/")]
        public void LoginTest_Empty_Password()
        {
            PersonalAlbum.Controllers.AccountController target = new PersonalAlbum.Controllers.AccountController();
            string username = "tal";
            string password = "";
            System.Nullable<bool> rememberMe = new System.Nullable<bool>(); // TODO: Initialize to an appropriate value
            string returnUrl = Guid.NewGuid().ToString();
            System.Web.Mvc.JsonResult actual;
            actual = target.Login(username, password, rememberMe, returnUrl);
            Assert.IsNotNull(actual);
            bool invalidFound = false;
            bool messageFound = false;
            foreach (PropertyDescriptor p in TypeDescriptor.GetProperties(actual.Data))
            {
                if (p.Name == "invalid")
                {
                    invalidFound = true;
                    Assert.AreEqual("true", p.GetValue(actual.Data).ToString());
                }
                if (p.Name == "message")
                {
                    messageFound = true;
                    Assert.IsTrue(p.GetValue(actual.Data).ToString().Length > 0);
                }
            }
            Assert.IsTrue(invalidFound);
            Assert.IsTrue(messageFound);
        }

        [TestMethod()]
        [HostType("ASP.NET")]
        [AspNetDevelopmentServerHost("%PathToWebRoot%\\ImagesSite\\ImagesSite", "/")]
        [UrlToTest("http://localhost:52161/")]
        public void LoginTest_Bad_Password()
        {
            PersonalAlbum.Controllers.AccountController target = new PersonalAlbum.Controllers.AccountController();
            string username = "tal";
            string password = Guid.NewGuid().ToString();
            System.Nullable<bool> rememberMe = new System.Nullable<bool>(); // TODO: Initialize to an appropriate value
            string returnUrl = Guid.NewGuid().ToString();
            System.Web.Mvc.JsonResult actual;
            actual = target.Login(username, password, rememberMe, returnUrl);
            Assert.IsNotNull(actual);
            bool invalidFound = false;
            bool messageFound = false;
            foreach (PropertyDescriptor p in TypeDescriptor.GetProperties(actual.Data))
            {
                if (p.Name == "invalid")
                {
                    invalidFound = true;
                    Assert.AreEqual("true", p.GetValue(actual.Data).ToString());
                }
                if (p.Name == "message")
                {
                    messageFound = true;
                    Assert.IsTrue(p.GetValue(actual.Data).ToString().Length > 0);
                }
            }
            Assert.IsTrue(invalidFound);
            Assert.IsTrue(messageFound);
        }

        /// <summary>
        ///A test for Lang
        ///</summary>
        [TestMethod()]
        [HostType("ASP.NET")]
        [AspNetDevelopmentServerHost("%PathToWebRoot%\\ImagesSite\\ImagesSite", "/")]
        [UrlToTest("http://localhost:52161/")]
        public void LangTest_Null_Lang()
        {
            PersonalAlbum.Controllers.AccountController target = new PersonalAlbum.Controllers.AccountController();
            string lang = null;
            string returnUrl = Guid.NewGuid().ToString();
            var result = target.Lang(lang, returnUrl);
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(RedirectResult));
        }

        [TestMethod()]
        [HostType("ASP.NET")]
        [AspNetDevelopmentServerHost("%PathToWebRoot%\\ImagesSite\\ImagesSite", "/")]
        [UrlToTest("http://localhost:52161/")]
        public void LangTest_Bad_Lang()
        {
            PersonalAlbum.Controllers.AccountController target = new PersonalAlbum.Controllers.AccountController();
            string lang = Guid.NewGuid().ToString();
            string returnUrl = null;
            var result = target.Lang(lang, returnUrl);
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
        }

        [TestMethod()]
        [HostType("ASP.NET")]
        [AspNetDevelopmentServerHost("%PathToWebRoot%\\ImagesSite\\ImagesSite", "/")]
        [UrlToTest("http://localhost:52161/")]
        public void LangTest_Good_Lang()
        {
            PersonalAlbum.Controllers.AccountController target = new PersonalAlbum.Controllers.AccountController();
            //I can't check that it actually changed the language but let it be...
            string lang = "Hebrew";
            string returnUrl = Guid.NewGuid().ToString();
            var result = target.Lang(lang, returnUrl);
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(RedirectResult));
        }

        /// <summary>
        ///A test for Index
        ///</summary>
        // TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,
        // http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,
        // whether you are testing a page, web service, or a WCF service.
        [TestMethod()]
        [HostType("ASP.NET")]
        [AspNetDevelopmentServerHost("%PathToWebRoot%\\ImagesSite\\ImagesSite", "/")]
        [UrlToTest("http://localhost:52161/")]
        public void IndexTest()
        {
            PersonalAlbum.Controllers.AccountController target = new PersonalAlbum.Controllers.AccountController();
            var actual = target.Index();
            Assert.IsNotNull(actual);
            Assert.AreEqual("Login", actual.ViewName);
        }

        /// <summary>
        ///A test for AccountController Constructor
        ///</summary>
        [TestMethod()]
        [HostType("ASP.NET")]
        [AspNetDevelopmentServerHost("%PathToWebRoot%\\ImagesSite\\ImagesSite", "/")]
        [UrlToTest("http://localhost:52161/")]
        public void AccountControllerConstructorTest1()
        {
            PersonalAlbum.Controllers.AccountController target = new PersonalAlbum.Controllers.AccountController();
        }


    }
}
